package com.dk.controller;

import com.dk.mapper.ClassinfoMapper;
import com.dk.pojo.*;
import com.dk.service.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.*;

@Controller
@RequestMapping("/user")
public class StudentController {

    @Autowired
    private StudentService studentService;
    @Autowired
    private ClassinfoService classinfoService;
    @Autowired
    private GradeService gradeService;
    @Autowired
            private KcService kcService;

    HttpSession session=null;
    @ResponseBody
    @RequestMapping("/findall")
    public List<Student> save14() {

        List<Student> userList = studentService.FindAll();

        return userList;

    }
    @ResponseBody
    @RequestMapping("/info")
    public Map<String,Object> grinfo(HttpServletRequest request) {
        session=request.getSession();
        String user = (String) session.getAttribute("user");
        Student find = studentService.Find(user);
        session.setAttribute("classid",find.getClassid());
        List<Student> list=new ArrayList<>();
        list.add(find);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",1000);
        map.put("data",list);
        return map;

    }
    @ResponseBody
    @RequestMapping("/cinfo")
    public Map<String,Object> cinfo(HttpServletRequest request) {
        session=request.getSession();
        String user = (String) session.getAttribute("user");
        String classid = studentService.Find(user).getClassid();
        Classinfo find = classinfoService.Find(classid);
        System.out.println(find);
        List<Classinfo> list=new ArrayList<>();
        list.add(find);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",1000);
        map.put("data",list);
        return map;

    }
    @ResponseBody
    @RequestMapping("/ginfo")
    public Map<String,Object> ginfo(HttpServletRequest request) {
        session=request.getSession();
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",1000);
        map.put("data",gradeService.Find((String) session.getAttribute("user")));
        return map;

    }
    @ResponseBody
    @RequestMapping("/kcb")
    public Map<String,Object> kcbinfo(HttpServletRequest request) {
        session=request.getSession();
        String classid = (String) session.getAttribute("classid");
        List<Kcb> list=kcService.FinaUserkcb(classid);
        Map<String,Object> map=new HashMap<>();
        map.put("data",list);
        return map;
    }









}
